import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      component: () => import('../views/home.vue')
    },
    {
      path: '/homestay',
      component: () => import('../views/list/homestay.vue')
    },
    {
      path: '/library',
      component: () => import('../views/list/library.vue')
    },
    {
      path: '/pick',
      component: () => import('../views/list/pick.vue')
    },
    {
      path: '/make',
      component: () => import('../views/list/make.vue')
    },
    {
      path: '/drink',
      component: () => import('../views/list/drink.vue')
    },
    {
      path: '/recommand',
      component: () => import('../views/list/recommand.vue')
    },
    {
      path: '/activity/:id',
      component: () => import('../views/detail.vue')
    },
    {
      path: '/room/:id',
      component: () => import('../views/detail.vue')
    },
    {
      path: '/library/:id',
      component: () => import('../views/detail.vue')
    },
    {
      path: '/homestay/:id',
      component: () => import('../views/detail.vue')
    },
    {
      path: '/scenery/:id',
      component: () => import('../views/scenery-detail.vue')
    },
    {
      path: '/iframe',
      component: () => import('../views/iframe.vue'),
      meta: { title: '全景' }
    }
  ]
})

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  } else {
    document.title = '天台茶旅'
  }
  next()
})

export default router
